/// <reference name="MicrosoftAjax.debug.js" />
/// <reference path="../../Stylesheet.debug.js" />
/// <reference path="../../Additions/Addition.debug.js" />
/// <reference path="../../Items/MItem.debug.js" />
/// <reference path="../../../Resources/js/jquery/jquery.debug.js" />

Type.registerNamespace("BM");

// VerticalTableDisplayAddition object

BM.VerticalTableDisplayAddition = function(item, data) {
    BM.VerticalTableDisplayAddition.initializeBase(this, [item, data]);
}


BM.VerticalTableDisplayAddition.prototype = {
    load: function() {
        BM.VerticalTableDisplayAddition.callBaseMethod(this, 'load');
        this.updateColumnWidth(this.item.getSiblings().length + 1);

    },

    unload: function() {
        BM.VerticalTableDisplayAddition.callBaseMethod(this, 'unload');
        this.updateColumnWidth(this.item.getSiblings().length);

    },

    getSiblingsHash: function() {
        return this.item.getSiblingId(-1).replace(/\:|\-/g, "");
    },

    updateColumnWidth: function(noOfColumns) {
        var percentage = 99 / (noOfColumns);
        for (var i = 0; i < document.styleSheets.length; i++) {
            this.updateInStylesheet(document.styleSheets[i], percentage);
        }
    },

    updateInStylesheet: function(stylesheet, percentage) {
        var rule = BM.Stylesheet.find(stylesheet, ".Table_" + this.getSiblingsHash(), true);
        if (rule) {
            BM.Stylesheet.set(rule, new Array("width", "left"), new Array(percentage + "%", percentage + "%"));
        }
    }
}

BM.VerticalTableDisplayAddition.registerClass("BM.VerticalTableDisplayAddition", BM.TableDisplayAddition);